<template>
  <table
    class="table table-sm table-striped table-hover"
    id="flight-refund-list"
  >
    <thead>
      <tr>
        <th class="d-none d-md-table-cell">退票单号</th>
        <th class="d-none d-md-table-cell">票号</th>
        <th>乘机人</th>
        <th class="d-none d-md-table-cell">PNR</th>
        <th class="bg-info text-center text-white">出发</th>
        <th class="bg-info text-center text-white">到达</th>
        <th class="bg-info text-center text-white">日期</th>
        <th class="bg-info text-center text-white">航班号</th>
        <th class="bg-info text-center text-white d-none d-md-table-cell">
          舱位
        </th>
        <th class="d-none d-md-table-cell">操作员</th>
        <th class="d-none d-md-table-cell">提交时间</th>
        <th class="d-none d-md-table-cell">状态</th>
        <th class="text-end d-none d-md-table-cell">航司预/实退</th>
        <th class="text-end d-none d-md-table-cell">实退客人</th>
        <th class="text-end d-none d-md-table-cell">利润</th>
        <th></th>
      </tr>
    </thead>
    <tbody>
      <tr
        v-for="(info, index) in dataList"
        :key="index"
        @click.stop="showDetail(info.id)"
      >
        <td class="d-none d-md-table-cell">{{ info.refundOrderNo }}</td>
        <td class="d-none d-md-table-cell">
          <strong>{{ info.balanceCode }}-{{ info.ticketNo }}</strong>
          <br />
          <i>
            <small>
              <span class="text-danger" v-if="info.intlTicket === 1">国际</span>
              <span v-else>国内</span>
              <span :class="{ 'text-danger': info.reasonCode === 4 }">{{
                getReasonCodeDesc(info.reasonCode)
              }}</span>
            </small>
          </i>
        </td>
        <td>
          <strong>{{ info.psgName }}</strong>
          <br />
          <span class="d-inline-block text-truncate small" style="max-width: 100px;">{{ showCustomerName(info, 1) }}</span>
        </td>
        <td class="d-none d-md-table-cell">{{ info.pnrNo }}</td>
        <td>
          <template v-for="(flt, index) in info.flights">
            <span :key="index">
              {{ flt.dport
              }}<span class="d-none d-md-inline">{{ flt.dportName }}</span>
              <br />
            </span>
          </template>
        </td>
        <td>
          <template v-for="(flt, index) in info.flights">
            <span :key="index">
              {{ flt.aport
              }}<span class="d-none d-md-inline">{{ flt.aportName }}</span>
              <br />
            </span>
          </template>
        </td>
        <td>
          <template v-for="(flt, index) in info.flights">
            <span :key="index">
              {{ flt.ddate }}
              <br />
            </span>
          </template>
        </td>
        <td>
          <template v-for="(flt, index) in info.flights">
            <span :key="index">
              {{ flt.flightNo }}
              <br />
            </span>
          </template>
        </td>
        <td class="d-none d-md-table-cell">
          <template v-for="(flt, index) in info.flights">
            <span :key="index">
              {{ flt.subclass }}
              <br />
            </span>
          </template>
        </td>
        <td class="d-none d-md-table-cell">{{ info.operator }}</td>
        <td class="d-none d-md-table-cell">
          {{ info.createTime.substring(5, 16) }}
        </td>
        <td class="d-none d-md-table-cell">
          {{ getStatus(info.status) }}
          <span class="small text-primary" v-if="info.payStatus === 2"
            >已销</span
          >
        </td>
        <td class="text-end d-none d-md-table-cell">
          <template v-if="info.airlineRefundAmount !== null">
            <strong>{{ info.airlineRefundAmount }}</strong>
          </template>
          <template v-else>{{ calcAirRefund(info) }}</template>
          /
          <strong>{{ info.airlineRefundAmountFinal }}</strong>
        </td>
        <td class="text-end d-none d-md-table-cell">
          <template v-if="info.passengerRefundAmount !== null">
            <strong>{{ info.passengerRefundAmount }}</strong>
          </template>
          <template v-else>{{ calcPsgRefund(info) }}</template>
        </td>
        <td class="text-end d-none d-md-table-cell">
          <template
            v-if="
              info.passengerRefundAmount !== null &&
              info.airlineRefundAmount != null
            "
          >
            <strong>{{
              calcProfit2(info.airlineRefundAmount, info.passengerRefundAmount)
            }}</strong>
          </template>
          <template v-else>{{ calcProfit(info) }}</template>
        </td>
        <td>
          <i class="mdi mdi-arrow-right fa-2"></i>
        </td>
      </tr>
    </tbody>
  </table>
</template>

<script>
import {
  showRefundOrderStatus,
  showReasonCodeDesc,
} from "@/api/flight-refund.js";
import { showCustomerName } from "@/common/common.js";

export default {
  props: {
    dataList: {
      type: Array,
    },
  },
  methods: {
    showDetail: function (id) {
      this.$router.push(`/h5/flt/refund/order/` + id);
    },
    getStatus: function (status) {
      return showRefundOrderStatus(status);
    },
    getReasonCodeDesc: function (status) {
      return showReasonCodeDesc(status);
    },
    showCustomerName: function (info, mode = 0) {
      return showCustomerName(info, mode);
    },
    calcAirRefund: function (info) {
      const ar = info.cost - info.airRefundCharge;
      return Math.round(ar * 100) / 100;
    },
    calcPsgRefund: function (info) {
      const pr = info.ticketAmount - info.airRefundCharge - info.serviceCharge;
      return Math.round(pr * 100) / 100;
    },
    calcProfit: function (info) {
      const profit = this.calcAirRefund(info) - this.calcPsgRefund(info);
      return Math.round(profit * 100) / 100;
    },
    calcProfit2: function (t1, t2) {
      const profit = t1 - t2;
      return Math.round(profit * 100) / 100;
    },
  },
};
</script>